﻿using System;
namespace IndexerApplication
{
    class IndexedNames
    {
        private string[] namelist = new string[size];
        static public int size = 10;
        public IndexedNames()
        {
            for (int i = 0; i < size; i++)
                namelist[i] = "N. A.";
        }
        public string this[int index]
        {
            get
            {
                string tmp;

                if (index >= 0 && index <= size - 1)
                {
                    tmp = namelist[index];
                }
                else
                {
                    tmp = "";
                }

                return (tmp);
            }
            set
            {
                if (index >= 0 && index <= size - 1)
                {
                    namelist[index] = value;
                }
            }
        }

        //static void Main(string[] args)
        //{
        //    /*IndexedNames names = new IndexedNames();
        //    names[0] = "Zara";
        //    names[1] = "Riz";
        //    names[2] = "Nuha";
        //    names[3] = "Asif";
        //    names[4] = "Davinder";
        //    names[5] = "Sunil";
        //    names[6] = "Rubic";
        //    for (int i = 0; i < IndexedNames.size; i++)
        //    {
        //        Console.WriteLine(names[i]);
        //    }
        //    Console.ReadKey();*/

        //    student student = new student();
        //    student["sss"] = null;
        //    var res = student["sss"];
        //    Console.WriteLine(res);
        //}
    }



    class student
    {
        private Dictionary<string, int> scoreDictionary = new Dictionary<string, int>();
        public int? this[string subject]
        {
            get
            {
                if (scoreDictionary.ContainsKey(subject))
                    return this.scoreDictionary[subject];
                else
                    return null;
            }
            set
            {
                if(value==null)
                    throw new ArgumentNullException("value");
                if (scoreDictionary.ContainsKey(subject))
                    this.scoreDictionary[subject] = value.Value;// 使用 Value 属性获取值
                else
                    this.scoreDictionary.Add(subject, value.Value);
            }
        }
    }

    class Prop
    {
        private int age;

        public int Age { get => age; set => age = value; }
    }

    namespace Demoprop
    {
        class Program
        {
            public abstract class Person
            {
                public abstract string Name { get; set; }
                public abstract int Age { get; set; }
            }
            public class Student : Person
            {
                public string Code { get; set; } = "N.A";
                public override string Name { get; set; } = "N.A";
                public override int Age { get; set; } = 0;
                public override string ToString()
                {
                    return $"Code:{Code},Name:{Name},Age:{Age}";
                }



                public bool  CanWork
                {
                    get { return Age>16; }
                }

            }

            static void Main(string[] args)
            {
                /*var s = new Student()
                {
                    Code = "001",
                    Name = "Zara",
                    Age = 18
                };
                System.Console.WriteLine($"Student Info:={s}");

                s.Age++;
                System.Console.WriteLine($"Student Info:={s}");
                System.Console.WriteLine(s.CanWork);*/

                //匿名方法
                Func<int,int,int> plus= delegate (int a,int b)
                {
                    return a + b; 
                };
                //Lambda表达式
                Func<int, int, int> plusS =( a,  b)=>{return a + b;};

                Console.WriteLine( plusS(3,6) );

            }
        }
    }
}

